﻿using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;
using System.Data;
using System.Text;


namespace IHISCETeim.Web.MachineSys.FTradeModel.ImortDate
{
    public partial class FTradeBalanceAddImport : PageBase
    {
        protected override string DWZRef
        {
            get
            {
                return "";
            }
        }

        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.none };
            }
        }

        protected int FCatheringId
        {
            get
            {

                return GetRequestValue<int>("FCatheringId", 0);
            }
        }
        protected int FTradeID
        {
            get
            {

                return GetRequestValue<int>("FTradeID", 0);
            }
        }
        protected string JiHao
        {
            get
            {

                return GetRequestValue<string>("JiHao", "");
            }
        }
        private FTradeCatheringInfo _objFx = null;

        protected FTradeCatheringInfo obj
        {
            get
            {
                if (_objFx == null)
                    _objFx = FTradeCatheringController.GetById(FCatheringId);
                return _objFx;
            }
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (GetRequestValue<string>("ajaxmethod", "") == "add")
            {
                addmenu();
            }
        }
        private void addmenu()
        {
            char[] caSplit = new char[] { ',' };
            string[] FTradeAgeIds = GetRequestValue<string>("FTradeAgeId", "").Split(caSplit);
            string[] BalanceMoneys = GetRequestValue<string>("BalanceMoney", "").Split(caSplit);

            List<FTradeBalanceInfo> list = new List<FTradeBalanceInfo>();
            for (int rowIndex = 0; rowIndex < FTradeAgeIds.Count(); rowIndex++)
            {
                FTradeBalanceInfo itm = new FTradeBalanceInfo();
                itm.FCatheringId = FCatheringId;
                itm.FTradeAgeId = Convert.ToInt32(FTradeAgeIds[rowIndex]);
                itm.BalanceMoney = Convert.ToDecimal(BalanceMoneys[rowIndex]);
                itm.RealName = base.User.RealName;
                itm.Remark = "";

                list.Add(itm);
            }

            decimal ShengYuJinE = GetRequestValue<decimal>("ShengYuJinE", 0m);


            bool msg = FTradeBalanceController.Add(list, ShengYuJinE);

            // AddLog(Permission.修改, obj, objTrade);

            if (msg)
            {//如果是换机,则进入 冲帐页面
                SuccessJson("已冲帐成功", "");
            }
            else
            {

                ErrorJson("冲帐失败");
            }
        }
    }
}